package com.example.demo.rabbitmq.config;

import org.springframework.amqp.core.*;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author LIN
 * @date 2022-12-12 16:46
 */
@Configuration
public class SimpleRabbitMqConfig {


    static final String topicExchangeName="mid_datasync";
    static final String queueName = "datasync_mid-user-core";

    @Bean
    Queue queue(){
        return new Queue(queueName,true);
    }

    @Bean
    FanoutExchange exchange(){
        return new FanoutExchange(topicExchangeName,true,false);
    }

    @Bean
    Binding binding(Queue queue,FanoutExchange exchange){
        return BindingBuilder.bind(queue).to(exchange);
    }

    @RabbitListener(queues = "${spring.queue}")
    public void receiveMessage(Message message){
        System.out.println(new String(message.getBody()));


    }
}
